package idv.arthur.WebService;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.util.Properties;

import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;


public class CallUtilWS01 {
	
	static String endpoint = "";
	
	private static void callUtilWS01() {
		final Properties prop = new Properties();
		InputStream input = null;
		try {
			input  = CallUtilWS01.class.getResourceAsStream("/wsdl.properties");
			prop.load(input);
			endpoint = prop.getProperty("wsdl");
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (input != null) {
				try {
					input.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}
	private static Call initial() throws ServiceException, MalformedURLException {

        final Service service = new Service();
        final Call call = (Call) service.createCall();
        call.setTargetEndpointAddress(new java.net.URL(endpoint));
        return call;
    }
	
	public static String getName(String employeeNumber) {
        try {
            final Object[] params = new Object[] {employeeNumber};
            final Call call = initial();

            String ret = (String) call.invoke(new QName("http://sys.cht.com/","getName"),params);
            if ( ret != null ) {
            	ret = ret.trim();
            } else {
            	ret = "沒找到";
            }

            return ret;
        }
        catch (Exception e) {
            e.printStackTrace();
            return "NULL";
        }
    }

	public static void main(String[] args) {
		callUtilWS01();
		System.out.println("Start.");
		System.out.println(getName("842297"));
	}

}
